/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.inf.ufg.view;

import br.inf.ufg.view.cadastros.TelaCadastroAssentos;
import br.inf.ufg.view.cadastros.TelaCadastroEventos;
import br.inf.ufg.view.cadastros.TelaCadastroLocal;
import br.inf.ufg.view.cadastros.TelaCadastroOperadores;
import br.inf.ufg.view.cadastros.TelaCadastroPontoVendas;
import br.inf.ufg.view.cadastros.TelaCadastroTiposAssentos;
import br.inf.ufg.view.genericas.TelaSobre;
import br.inf.ufg.view.relatorio.TelaRelatorioTotalVendas;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author umarley.faria
 */
public class Principal extends javax.swing.JFrame {

    /**
     * Creates new form TelaPrincipal
     */
    public Principal() {
        initComponents();
        //Tela principal inicia maximizado
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jToolBar1 = new javax.swing.JToolBar();
        btnNovoEvento = new javax.swing.JButton();
        btnAdicionarLocal = new javax.swing.JButton();
        btnNovaVenda = new javax.swing.JButton();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnuCadastros = new javax.swing.JMenu();
        mnuCadLocal = new javax.swing.JMenu();
        mnuItemLocal = new javax.swing.JMenuItem();
        mnuItemTiposAssentos = new javax.swing.JMenuItem();
        mnuItemAssentos = new javax.swing.JMenuItem();
        mnuCadEventos = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mnuCadPontoVendas = new javax.swing.JMenuItem();
        mnuCadOperadores = new javax.swing.JMenuItem();
        mnuMovimentos = new javax.swing.JMenu();
        mnuMovVendas = new javax.swing.JMenuItem();
        mnuReport = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        mnuOptions = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        mnuSobre = new javax.swing.JMenuItem();
        mnuSair = new javax.swing.JMenu();

        jMenu1.setText("jMenu1");

        jMenuItem2.setText("jMenuItem2");

        jMenu2.setText("jMenu2");

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Magic Ticket Seller - Vendas de Ingressos");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jToolBar1.setRollover(true);

        btnNovoEvento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/inf/ufg/view/images/1399333931_add-event.png"))); // NOI18N
        btnNovoEvento.setToolTipText("Adicionar Novo Evento");
        btnNovoEvento.setFocusable(false);
        btnNovoEvento.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovoEvento.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovoEvento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoEventoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnNovoEvento);

        btnAdicionarLocal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/inf/ufg/view/images/1399333413_local.png"))); // NOI18N
        btnAdicionarLocal.setToolTipText("Adicionar Local de Eventos");
        btnAdicionarLocal.setFocusable(false);
        btnAdicionarLocal.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAdicionarLocal.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAdicionarLocal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarLocalActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAdicionarLocal);

        btnNovaVenda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/inf/ufg/view/images/1399334553_ticket.png"))); // NOI18N
        btnNovaVenda.setToolTipText("Vender Ingressos");
        btnNovaVenda.setFocusable(false);
        btnNovaVenda.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovaVenda.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovaVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovaVendaActionPerformed(evt);
            }
        });
        jToolBar1.add(btnNovaVenda);

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 376, Short.MAX_VALUE)
        );

        mnuCadastros.setText("Cadastros");

        mnuCadLocal.setText("Locais");

        mnuItemLocal.setText("Local");
        mnuItemLocal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuItemLocalMouseClicked(evt);
            }
        });
        mnuItemLocal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemLocalActionPerformed(evt);
            }
        });
        mnuCadLocal.add(mnuItemLocal);

        mnuItemTiposAssentos.setText("Tipos de Assentos");
        mnuItemTiposAssentos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemTiposAssentosActionPerformed(evt);
            }
        });
        mnuCadLocal.add(mnuItemTiposAssentos);

        mnuItemAssentos.setText("Assentos");
        mnuItemAssentos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemAssentosActionPerformed(evt);
            }
        });
        mnuCadLocal.add(mnuItemAssentos);

        mnuCadastros.add(mnuCadLocal);

        mnuCadEventos.setText("Eventos");
        mnuCadEventos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadEventosActionPerformed(evt);
            }
        });
        mnuCadastros.add(mnuCadEventos);
        mnuCadastros.add(jSeparator1);

        mnuCadPontoVendas.setText("Ponto de Vendas");
        mnuCadPontoVendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadPontoVendasActionPerformed(evt);
            }
        });
        mnuCadastros.add(mnuCadPontoVendas);

        mnuCadOperadores.setText("Operadores");
        mnuCadOperadores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadOperadoresActionPerformed(evt);
            }
        });
        mnuCadastros.add(mnuCadOperadores);

        jMenuBar1.add(mnuCadastros);

        mnuMovimentos.setText("Movimentos");

        mnuMovVendas.setText("Vendas de Ingressos");
        mnuMovimentos.add(mnuMovVendas);

        jMenuBar1.add(mnuMovimentos);

        mnuReport.setText("Relatórios");

        jMenuItem1.setText("Quantidade de Ingressos Vendidos");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mnuReport.add(jMenuItem1);

        jMenuBar1.add(mnuReport);

        mnuOptions.setText("Opções");
        jMenuBar1.add(mnuOptions);

        jMenu5.setText("Ajuda");

        mnuSobre.setText("Sobre");
        mnuSobre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuSobreMouseClicked(evt);
            }
        });
        mnuSobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSobreActionPerformed(evt);
            }
        });
        jMenu5.add(mnuSobre);

        jMenuBar1.add(jMenu5);

        mnuSair.setText("Sair");
        mnuSair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuSairMouseClicked(evt);
            }
        });
        mnuSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSairActionPerformed(evt);
            }
        });
        jMenuBar1.add(mnuSair);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
            .addComponent(jDesktopPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jDesktopPane1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuItemLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemLocalActionPerformed
         abreCadastroLocal();
    }//GEN-LAST:event_mnuItemLocalActionPerformed

    private void btnNovoEventoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoEventoActionPerformed
        abreCadastroEventos();
    }//GEN-LAST:event_btnNovoEventoActionPerformed

    private void mnuSobreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSobreActionPerformed
        abreSobre();
    }//GEN-LAST:event_mnuSobreActionPerformed

    private void mnuSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSairActionPerformed
        this.sairSistema();
    }//GEN-LAST:event_mnuSairActionPerformed

    private void mnuSairMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuSairMouseClicked
       this.sairSistema();
    }//GEN-LAST:event_mnuSairMouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        sairSistema();
    }//GEN-LAST:event_formWindowClosing

    private void mnuItemLocalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuItemLocalMouseClicked
       // TODO add your handling code here:
    }//GEN-LAST:event_mnuItemLocalMouseClicked

    private void btnAdicionarLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarLocalActionPerformed
        abreCadastroLocal();
    }//GEN-LAST:event_btnAdicionarLocalActionPerformed

    private void mnuSobreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuSobreMouseClicked
        abreSobre();
    }//GEN-LAST:event_mnuSobreMouseClicked

    private void mnuItemTiposAssentosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemTiposAssentosActionPerformed
        abreCadastroTiposAssentos();
    }//GEN-LAST:event_mnuItemTiposAssentosActionPerformed

    private void mnuItemAssentosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemAssentosActionPerformed
        abreCadastroAssentos();
    }//GEN-LAST:event_mnuItemAssentosActionPerformed

    private void mnuCadEventosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCadEventosActionPerformed
        abreCadastroEventos();
    }//GEN-LAST:event_mnuCadEventosActionPerformed

    private void mnuCadPontoVendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCadPontoVendasActionPerformed
        abreCadastroPontoVendas();
    }//GEN-LAST:event_mnuCadPontoVendasActionPerformed

    private void mnuCadOperadoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCadOperadoresActionPerformed
        try {
            abreCadastroOperadores();
        }
        catch(Exception e)
        {}
    }//GEN-LAST:event_mnuCadOperadoresActionPerformed

    private void btnNovaVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovaVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnNovaVendaActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        abreRelatorioTotalVendas();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    
    private void abreCadastroLocal(){
        TelaCadastroLocal janela = new TelaCadastroLocal();
        janela.setResizable(false);
        janela.setLocationRelativeTo(this);
        janela.setVisible(true);
    }
    
    
    private void abreSobre(){
        
        TelaSobre sobre = new TelaSobre();
        sobre.setVisible(true);
        
        
        
    }
    
    
    private void abreCadastroTiposAssentos(){
        
        TelaCadastroTiposAssentos tela = new TelaCadastroTiposAssentos();
        tela.setVisible(true);
        
    }
    
    
    private void abreCadastroAssentos(){
        
        TelaCadastroAssentos tela = new TelaCadastroAssentos();
        tela.setVisible(true);
        
    }
    
    
   private void abreCadastroEventos(){
        TelaCadastroEventos janela = new TelaCadastroEventos();
        janela.setVisible(true);
    }
    
    private void abreCadastroPontoVendas(){
        TelaCadastroPontoVendas janela = new TelaCadastroPontoVendas();
        janela.setResizable(false);
        janela.setLocationRelativeTo(this);
        janela.setVisible(true);
    }
    
    
    private void abreCadastroOperadores() throws SQLException{
        TelaCadastroOperadores janela = new TelaCadastroOperadores();
        janela.setResizable(false);
        janela.setLocationRelativeTo(this);
        janela.setVisible(true);
    }
    
    private void abreRelatorioTotalVendas(){
        TelaRelatorioTotalVendas janela = new TelaRelatorioTotalVendas();
        janela.setResizable(false);
        janela.setLocationRelativeTo(this);
        janela.setVisible(true);
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    
    private void sairSistema(){
       
        
        //JOptionPane.showMessageDialog(null, "Teste");
        int resposta = JOptionPane.showConfirmDialog(rootPane, "Deseja Realmente sair do sistema?", "Pergunta", JOptionPane.CANCEL_OPTION);
        
        if(resposta == JOptionPane.YES_OPTION){
            System.exit(0);
        }
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdicionarLocal;
    private javax.swing.JButton btnNovaVenda;
    private javax.swing.JButton btnNovoEvento;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem mnuCadEventos;
    private javax.swing.JMenu mnuCadLocal;
    private javax.swing.JMenuItem mnuCadOperadores;
    private javax.swing.JMenuItem mnuCadPontoVendas;
    private javax.swing.JMenu mnuCadastros;
    private javax.swing.JMenuItem mnuItemAssentos;
    private javax.swing.JMenuItem mnuItemLocal;
    private javax.swing.JMenuItem mnuItemTiposAssentos;
    private javax.swing.JMenuItem mnuMovVendas;
    private javax.swing.JMenu mnuMovimentos;
    private javax.swing.JMenu mnuOptions;
    private javax.swing.JMenu mnuReport;
    private javax.swing.JMenu mnuSair;
    private javax.swing.JMenuItem mnuSobre;
    // End of variables declaration//GEN-END:variables
}
